/**
 * 初始化
 */
$(function () {
    setPost();
    init();
});

/**
 * 加载layui样式
 */
function init() {
    layui.use(['form', 'laydate', 'dtree'], function () {

        var form = layui.form
            , dtree = layui.dtree;

    });
}

/**
 * 设置部门
 */
function setDeptId() {
    var deptId = $("#deptId").val();
    var deptName = $("#deptName").val();
    var title = "选择部门信息",
        url = prefixOpen + "/web!system!user!deptTree!deptTree@deptId=" + deptId + "&deptName=" + deptName,
        width = "20%",
        height = "40%";
    //  打开新窗口
    layTool.openDialog(title, url, width, height, getDeptDate);
}


/**
 * @Description: 打开添加树callBack 事件
 * @Param:
 * @return:
 * @Author: Mr.Yan
 * @Date: 2018/12/5
 */

function getDeptDate(index, layero) {
    // 获取添加 部门树 页面参数函数
    var body = layTool.getChildFrame("body", index);
    $("#deptId").val(body.find('#deptId').val());
    $("#deptName").val(body.find('#deptName').val());
    layTool.closeLayer(index);
}

/**
 * @Description: 设置岗位options
 * @Param:
 * @return:
 * @Author: Mr.Yan
 * @Date: 2018/12/6
 */

function setPost() {
    layui.use(['form',], function () {
        var form = layui.form;
        $.ajax({
            url: prefixPost + "/findAll",
            type: "GET",
            async: false,
            success: function (data) {
                if (!isEmpty(data)) {
                    var errcode = data.errcode;
                    var errmsg = data.errmsg;
                    if (errcode == "0") {
                        var posts = data.data.posts;
                        for (var i = 0; i < posts.length; i++) {
                            var postId = posts[i].postId;
                            var postName = posts[i].postName;
                            var option = "<option value=\"" + postId + "\">" + postName + "</option>";
                            $("#postId").append(option);
                        }
                        form.render();
                    } else {
                        AjaxException(errmsg);
                    }
                }
            },
            error: function () {
                AjaxErro();
            }
        })
    });
}

/**
 * @Description: 设置角色
 * @Param:
 * @return:
 * @Author: Mr.Yan
 * @Date: 2018/12/6
 */
function setRole() {
    var roleIds = $("#roleIds").val();
    var roleNames = $("#roleNames").val();
    var title = "选择角色信息",
        url = prefixOpen + "/web!system!user!setRole!setRole@roleIds=" + roleIds +"&roleNames=" + roleNames,
        width = "20%",
        height = "40%";
    //  打开新窗口
    layTool.openDialog(title, url, width, height, getRoleDate);
}

/**
 * @Description: 打开角色回调函数
 * @Param:
 * @return:
 * @Author: Mr.Yan
 * @Date: 2018/12/6
 */

function getRoleDate(index, layero) {
    // 获取添加 部门树 页面参数函数
    var body = layTool.getChildFrame("body", index);
    $("#roleIds").val(body.find('#roleIds').val());
    $("#roleNames").val(body.find('#roleNames').val());
    layTool.closeLayer(index);
}
